package com.jp.algorithm.sort;

public class BubbleSort {


    public static  void sort(int[] a) {
        for (int i = a.length-1 ; i > 0 ; i--) {
            boolean changed=false;
            for (int j = 1; j <= i; j++) {
                if (a[j - 1] > a[j]) {
                    int tmp = a[j - 1];
                    a[j - 1] = a[j];
                    a[j] = tmp;
                    changed=true;
                }
            }
            if(changed==false)
                return;
        }

        print(a);
    }

    public static  void print(int[] a) {
        for (int i = 0; i < a.length; i++) {
            System.out.println(a[i]);
        }
    }


    public static void main(String[] args) {
        //int[] a={5,4,19,30,2,10,33,80};
        int[] a={5,4,19,30,2};
        sort(a);

    }

}
